<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Request;

class Classs extends Api
{
	public function tj()
    {
    	$list = model('classs')->field('id')->select()->toArray();
    	$arr = [];
    	foreach ($list as $k=>$v)
    	{
    		$pr = model('product')->field('id')->where('classs_id','=',$v['id'])->select();
    		if($pr){
    			$arr[$k]['id'] = $v['id'];
    			$arr[$k]['num'] = count($pr);
    		}else{
    			$arr[$k]['id'] = $v['id'];
    			$arr[$k]['num'] = 0;
    		}
    	}
    	model('classs')->saveAll($arr);
    	exit;
    }
}
